package ex02.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GestorConsultas {
	
	private Connection conn;
	public GestorConsultas(Connection conn) {	
		this.conn = conn;
	}
	
	public void consulta(String sql, ProcesadorFilas proFilas) {		
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {			
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();			
			while (rs.next()) {
				proFilas.procesarFila(rs);
			}			
			rs.close();
			ps.close();						
		}
		catch (SQLException ex) {
			ex.printStackTrace();
		}
		finally {
			try {
				conn.close();
			}
			catch (SQLException ex) {
				ex.printStackTrace();
			}
		}
	}
	
}
